package randUtils

import (
	"math/rand"
	"time"
)

const NUMBERCHAR string = "0123456789"
const LETTERCHAR string = "abcdefghijklmnopqrstuvwxyz"
const CHECKNOCHAR string = "3456789abcdefghjkmnpqrstuvwxy"

func init() {
	rand.Seed(time.Now().UnixNano())
}
func getNumber() int {
	return rand.Intn(9)
}

// 随机生成数字
func RandNumber(l int) string {
	return randData(l, NUMBERCHAR)
}

// 随机字母
func RandLetter(l int) string {
	return randData(l, LETTERCHAR)
}

// 随机字母数字
func RandLetterNumber(l int) string {
	return randData(l, LETTERCHAR+NUMBERCHAR)
}

// 随机验证码
func RandCheckNo(l int) string {
	return randData(l, CHECKNOCHAR)
}

// 生成随机数
func randData(l int, dataFrom string) string {
	result := make([]rune, l)
	l2Number := len(dataFrom)
	st := []rune(dataFrom)

	for i := 0; i < l; i++ {
		result[i] = st[rand.Intn(l2Number)]
	}
	return string(result)
}
